package com.wutong.erb.entity.user;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonValue;
import com.wutong.erb.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 用户实体类，对应数据库中的 user 表
 *
 * @author wutong
 */
@TableName(value = "user", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = false)
public class User extends BaseEntity {
    /**
     * 用户名   唯一
     */
    private String username;
    /**
     * 密码散列值  加密存储
     */
    private String passwordHash;
    /**
     * 性别 1-男 2-女 3-未知
     */
    @EnumValue
    @TableField("sex")
    private Sex sex;
    /**
     * 手机号
     */
    @TableField(value = "phone")
    private String phone;
    /**
     * 邮箱    唯一
     */
    @TableField(value = "email")
    private String email;
    /**
     * 用户类型 1-普通用户 2-教师 3-管理员
     */
    @EnumValue
    @TableField("user_type")
    private UserType userType;
    @TableField(value = "nickname")
    private String nickname;
    /**
     * 微信openid
     */
    @TableField(value = "wechat_openid")
    private String wechatOpenid;
    /**
     * QQ openid
     */
    @TableField(value = "qq_openid")
    private String qqOpenid;
    /**
     * 头像url
     */
    @TableField(value = "avatar_url")
    private String avatarUrl;
    /**
     * 真实姓名
     */
    @TableField(value = "real_name")
    private String realName;
    /**
     * 账户状态 1-正常 2-禁用
     */
    @EnumValue
    @TableField("status")
    private UserStatus status;

    @TableField(exist = false)
    private Teacher teacherProfile;

    @Getter
    @RequiredArgsConstructor
    public enum UserStatus {
        NORMAL(1, "正常"),
        DISABLE(0, "禁用"),
        EXPIRED(2, "过期"),
        LOCKED(3, "锁定");

        @EnumValue
        private final Integer key;
        @JsonValue
        private final String value;
    }

    @Getter
    @RequiredArgsConstructor
    public enum UserType {
        NORMAL(1, "普通用户"),
        TEACHER(2, "教师"),
        ADMIN(3, "管理员");

        @EnumValue
        private final Integer key;
        @JsonValue
        private final String value;
    }

    @Getter
    @RequiredArgsConstructor
    public enum Sex {
        MALE(1, "男"),
        FEMALE(2, "女"),
        UNKNOWN(3, "未知");

        @EnumValue
        private final Integer key;

        @JsonValue
        private final String value;
    }
}
